import allure
from appium.webdriver.common.appiumby import AppiumBy

from .edit_member_info_page import EditMemberInfoPage
from ..base.base import Base


class ManageContactPage(Base):
    __MEMBERS = (AppiumBy.ID, 'com.tencent.wework:id/g1b')
    __CREATOR = '周杰'

    @allure.step("跳转至指定用户信息页")
    def goto_clarity_member_info_page(self, name):
        self.swipe_find(name).click()

        image_path = self.screenshot()
        allure.attach.file(image_path, name=f"跳转指定用户{name}编辑", attachment_type=allure.attachment_type.PNG)
        return EditMemberInfoPage(self.driver)

    @allure.step("跳转至用户信息页")
    def goto_member_info_page(self):
        self.find_ele(self.__MEMBERS).click()

        image_path = self.screenshot()
        allure.attach.file(image_path, name="跳转用户编辑页", attachment_type=allure.attachment_type.PNG)
        return EditMemberInfoPage(self.driver)

    @allure.step("获取指定用户")
    def get_member(self, name):
        try:
            ele = self.swipe_find(name)
            return ele
        except Exception:
            return None

    # @allure.step("删除所有成员")
    # def delete_all_member(self):
    #     eles = self.find_eles(self.__MEMBERS)
    #     length = len(eles)
    #     if length > 1:
    #         for i in range(length):
    #             ele_name = eles[i].text
    #             if ele_name != self.__CREATOR:
    #                 self.goto_clarity_member_info_page(ele_name).delete_member()
